#include <iostream>
using namespace std;
int main() {
	int a[4], i, j, ma, mi, m, f,input;
	int sum = 0;
cin >> input;
a[0] = (input / 1000) % 10;
a[1] = (input / 100) % 10;
a[2] = (input / 10) % 10;
a[3] = input % 10;

	f = a[0] * 1000 + a[1] * 100 + a[2] * 10 + a[3];
	while (f != 6174) {
		for (i = 0; i < 4; i++) {
			for (j = 0; j < (3 - i); j++) {
				if (a[j] < a[j + 1]) {
					m = a[j];
					a[j] = a[j + 1];
					a[j + 1] = m;
				}
			}
		}
		mi = a[0] + a[1] * 10 + a[2] * 100 + a[3] * 1000;
		ma = a[3] + a[2] * 10 + a[1] * 100 + a[0] * 1000;
		f = ma - mi;
		int temp = f;
		a[3] = temp % 10; temp /= 10;
		a[2] = temp % 10; temp /= 10;
		a[1] = temp % 10; temp /= 10;
		a[0] = temp % 10;
		sum++;
	}
	cout << sum;
	return 0;
}



